package com.cqs.learning.spring.cloud.producer.service;

import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author lixw
 * @date 2020/3/27 8:19
 */
@Service
@Log4j2
public class TestOtService {
    private static final AtomicInteger cnt = new AtomicInteger(0);

    @Autowired
    private ServiceDemo serviceDemo;


    public int cnt() {
        return 100;
    }

    public int cnt3() {
        for (int i = 0; i < 1000; i++) {
            cnt.get();
        }
        int result = cnt.addAndGet(1);
        log.info("计算结果:{}", result);
        return result;
    }

    public int cnt2() {
        try {
            TimeUnit.MILLISECONDS.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return serviceDemo.cnt2();
    }
}
